#include <iostream>
using namespace std;
int N,M,ind,lr;
bool arr[100000];

typedef struct intNode
{
    int data;
    intNode *next;
    intNode *pre;
} intNode;

typedef struct int_Doublelink
{
    intNode *head;
} IDL;

intNode *curNode;

bool left(intNode *a, intNode *b)
{
    a->next = b;
    a->pre = b->pre;
    b->pre = a;
    if(a->pre) a->pre->next = a;
    return true;
}
bool right(intNode *a, intNode *b)
{
    a->next = b->next;
    a->pre = b;
    b->next = a;
    if(a->next) a->next->pre = a;
    return true;
}
bool insertNode(IDL *L, int data, int index, int lr)
{
    intNode *newNode = new intNode();
    newNode->data = data;
    if (L->head == NULL)
    {
        L->head = newNode;
        return true;
    }
    curNode = L->head;
    while (true)
    {
        if (index == curNode->data)
        {
            if (lr == 0)
            {
                if (index == L->head->data)
                {
                    L->head = newNode;
                }
                left(newNode, curNode);
            }
            else
                right(newNode, curNode); 
            break;
        }
        curNode = curNode->next;
    }
    return true;
}

int main(int argc, char const *argv[])
{
    IDL *L = new IDL();
    L->head=new intNode();
    L->head->data=1;
    scanf("%d", &N);
    for (int i = 2; i <= N; i++)
    {
        scanf("%d %d", &ind, &lr);
        insertNode(L,i,ind,lr);
    }
    scanf("%d", &M);
    while (M--)
    {
        scanf("%d",&ind);
        arr[ind] = 1;
    }
    curNode = L->head;
    while (curNode)
    {
        if(!arr[curNode->data]) printf("%d ",curNode->data);
        curNode = curNode->next;
    }
    return 0;
}
